<?php

namespace App\Http\Controllers\Admin;

use App\Repository\Product\GoodsNoticeRepository as model;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller as BaseController;
use App\Repository\UploadRepository;

// 分销商
class GoodsNoticeController extends BaseController
{
  private $repoist;
  public function __construct(model $model)
  {
    $this->repoist = $model;
  }
  public function store(Request $request)
  {
    return $this->repoist->add($request);
  }
  public function index(Request $request)
  {
    $where = [];
    // if (!empty($request->get('name'))) {
    //   $where['where']['name'] = $request->get('name');
    //   // $where['where'] = ['sup_orderno' => $request->get('sup_orderno')];
    // }
    //时间验证 
    $data =  $this->repoist->index($request);
    return $data;
  }

  public function save(Request $request)
  {
    if (!$request->get('id')) {
      return $this->returnMsg(1, '请传递id参数');
    }
    $where = [
      'id' => $request->get('id'),
      // 'shop_id' => $request->user->shop_id
    ];
    return $this->repoist->edit($where, $request);
  }
  public function  show(Request $request, $id)
  {
    $where = [
      'id' => $id
    ];
    //查询一条数据
    $field = ['*'];
    $return = $this->repoist->getOne($where, $field);
    // if(!empty($return)){
    //   $return[''] = (int)$return['']
    // }
    // $return = json_decode(json_encode($return), true);
    return $this->returnMsg(200, '查询成功', $return);
  }
  public function  showOne($id)
  {
    $where = ['id' => $id];
    //查询一条数据
    $return = $this->repoist->getOne($where, ['*']);
    return $this->returnMsg(200, '查询成功', $return);
  }

  public function listss(Request $request)
  {
    $where = [];
    if (!empty($request->get('name'))) {
      $where['where'] = ['name' => $request->get('name')];
    }

    $return = $this->repoist->lists($where);
    return $return;
  }

  public function destroy(Request $request, $id)
  {
    if (!$id) {
      return $this->returnMsg(1, '请传递参数');
    }
    $where = [
      'id' => $id,
      'shop_id' => $request->user->shop_id
    ];
    return $this->repoist->del($where);
  }
  public function updateStatus(Request $request, $id)
  {
    $where = [
      'id' => $id,
      'shop_id' => $request->user->shop_id
    ];
    // 需要修改两个地方 一个是状态 一个 app是否上架
    $update = [
      'status' => $request->get('status'),
    ];

    return $this->repoist->edit($where, $update);
  }
}
